constructive algorithms geometry math *1300

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;


using namespace __gnu_pbds;

template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define pb push_back
#define ii pair<int, int>
#define int long long
#define fi first
#define se second
#define fou(i, a, b) for (int i = a; i <= b; ++i)
#define fod(i, a, b) for (int i = a; i >= b; --i)
#define all(v) (v).begin(), (v).end()
#define MAX_N 10000000
#define el '\n'

typedef long long ll;
const int mxN = 1e5 + 9;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)4e18 + 7LL;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0} ;


struct DSU {
    vector<int> par, rank;
    DSU() {}
    DSU(int n): par(n, -1), rank(n, -1) {}
    int root(int u) {
        return (par[u] < 0 ? u : par[u] = root(par[u]));
    }

    int sameSet(int u, int v) {
        return root(u) == root(v);
    }

    int size(int u) {
        return -par[root(u)];
    }
    int unite(int u, int v) {
        int x = root(u);
        int y = root(v);
        if (x == y) return 0;


        if (par[x] > par[y]) {
            swap(x,y);
        }

    //    par[x] += par[y];
        par[y] = x;

        return 1;
    }
};

template<class T> T Kruskal(int n2, vector<pair<T, pair<int, int>>> edges) {
    sort(all(edges));
    T ans = 0;
    DSU dsu(n2 + 1);
    for (auto &d : edges) {
        int x = d.se.fi;
        int y = d.se.se;
        if (dsu.unite(x, y)) {
            ans = max(ans, d.fi);
        }
    }
    return (dsu.size(1) == n2 ? ans : -1);
}


int TREE[mxN];
void update(int id, int l, int r, int i, int val) {
    if (i > r || i < l) return;
    if (l == r) {
        TREE[id] = val;
        return;
    }
    int m = (l + r) >> 1;
    update(2 * id, l, m, i, val);
    update(2 * id + 1 ,m + 1, r, i, val);
    TREE[id] = max(TREE[2 * id], TREE[2 * id + 1]);
}

int query(int id, int l, int r, int x, int y) {
    if (l > y || r < x ) return -1;
    if (l >= x && r <= y) return TREE[id];
    int m = (l + r) >> 1;
    int res = query(2 * id, l, m, x, y) ;
    int res2 = query(2 * id + 1, m + 1, r, x, y);
    return max(res, res2);
} 


int a[mxN];
int l[mxN], r[mxN];
int pref[mxN], pref2[mxN];
int32_t main() {
    if (fopen("bonus.inp", "r")) {
        freopen("bonus.inp" ,"r", stdin);
        freopen("bonus.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k; cin >> n >> k;
    if (n == 3) {
        cout << "1 2 3";
    } else if (n == 4) {
        if (abs(90 - k) < abs(45 - k)) {
            cout << "1 2 3";
        } else {
            cout << "1 2 4";
        }
    } else {
        int tmp = 2 + (90 + n * k) / 180;
        if (tmp > n) tmp = n;
        if (tmp < 3) tmp = 3;
        cout << "2 1 " << tmp ;
    }
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions